<template>
    <section>
        <el-form :inline="true" :model="PropertyEditForm" :rules="propertyRules" ref="PropertyEditForm">
                <el-form-item label="属性名" prop="PropertyName">
                    <el-select v-model="PropertyEditForm.PropertyName" clearable placeholder="请选择属性名">
                        <el-option v-for="item in PropertyEditForm.PropertyNames" :label="item.label" :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="属性值" prop="PropertyValue">
                    <el-input v-model="PropertyEditForm.PropertyValue"></el-input>
                </el-form-item>
            </el-form>
            <el-col :span="24" style="margin-bottom: 10px;">
                <el-button type="primary" @click="submitForm('PropertyEditForm')">更新商品</el-button>
                <el-button style="float:right;" @click="returnProperty">返回</el-button>
            </el-col>
    </section>
</template>
<script>
    export default {
        data() {
            return {
                imgName: '',
                visible: false,
                previewVisible: false,
                previewImageUrl: "",
                PropertyEditForm: {
                    PropertyName: '',
                    PropertyValue: '',
                    PropertyNames: [
                        {
                            value: '选项1',
                            label: '黄金糕'
                        },
                        {
                            value: '选项2',
                            label: '黄金糕sd'
                        }
                    ]
                },
                propertyRules: {
                    PropertyName: [
                        { required: true, message: '请选择属性名', trigger: 'change' }
                    ],
                    PropertyValue: [
                        { required: true, message: '请输入属性值', trigger: 'change blur' }
                    ]
                }
            }
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        alert('submit!');
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },

            handlePreview(file) {
                this.previewImageUrl = file.url;
                this.previewVisible = true;
            },
            handSuccess(response, file, fileList) {
                fileList.length = 0;
                fileList.push(file);
            },
            handleView(name) {
                this.imgName = name;
                this.visible = true;
            },
            returnProperty() {
                this.$router.push('/products/undefined/product_properties');
            }
        }
    }
</script>